package com.geek.ch06.anno;

import com.geek.entity.Orders;
import com.geek.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersMapper {

    //通过用户ID，查询其所有的订单信息
    @Select("select * from orders where user_id = #{uid}")
    @Results({
            @Result(id = true , property = "id" , column = "id"),
            @Result(column = "id" , property = "orderDetails" , javaType = List.class ,
                many = @Many(select = "com.geek.ch06.anno.OrderDetailMapper.findDetailsByOid"))
    })
    public List<Orders> findOrdersByUid(int uid);

    //<!-- 注解方式作业1：查询订单信息及其下单者信息  OO  -->
    @Select("select * from orders where id = #{oid}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "user",column = "user_id",javaType = User.class,
                    one = @One(select = "com.geek.ch06.anno.UserMapper.selectUser"))
    })
    Orders selectOrderAndUserById(Integer oid);

    //<!-- 注解方式作业2：每个订单中包含的商品信息  OM -->
    @Select("select * from orders where id = #{id}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "orderDetails",column = "id",javaType = List.class,
                    many = @Many(select = "com.geek.ch06.anno.OrderDetailMapper.selectOrderDetailAndItemById"))
    })
    Orders selectOrderAndItemById(Integer id);

}
